﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace GeneticAlgorithm
{
    public partial class MainForm : Form
    {
        private List<int> _inputs = new List<int>();
        private List<Item> _results = new List<Item>();

        public MainForm()
        {
            InitializeComponent();
            SetStartValues();
        }

        private void SetStartValues()
        {
            var startValues = Generator.GenerateRelevance();
            numericUpDown1.Value = startValues[0];
            numericUpDown2.Value = startValues[1];
            numericUpDown3.Value = startValues[2];
            numericUpDown4.Value = startValues[3];
            numericUpDown5.Value = startValues[4];
            numericUpDown6.Value = startValues[5];
            numericUpDown7.Value = startValues[6];
            numericUpDown8.Value = startValues[7];
            numericUpDown9.Value = startValues[8];
            numericUpDown10.Value = startValues[9];
        }

        private void Form1_Load(object sender, System.EventArgs e)
        {
        }

        private void OnButtonClick(object sender, System.EventArgs e)
        {
            outputTb.Text = "";
            var input = new List<int>()
                {
                    int.Parse(numericUpDown1.Text),
                    int.Parse(numericUpDown2.Text),
                    int.Parse(numericUpDown3.Text),
                    int.Parse(numericUpDown4.Text),
                    int.Parse(numericUpDown5.Text),
                    int.Parse(numericUpDown6.Text),
                    int.Parse(numericUpDown7.Text),
                    int.Parse(numericUpDown8.Text),
                    int.Parse(numericUpDown9.Text),
                    int.Parse(numericUpDown10.Text),
                };
            var algorithm = new Algorithm(input);
            var result = algorithm.GetAdvice();
            using (var writer = new StreamWriter("log" + DateTime.Now.Millisecond + ".txt"))
            {
                writer.WriteLine("Релевантности по категориям:");
                foreach (var inputValue in input)
                {
                    writer.Write(inputValue + " ");
                }
                writer.WriteLine();
                foreach (var item in result)
                {
                    var product =
                        string.Format(
                            "Товар №{0}:\nкатегория:{1}\nназвание:{2},\nцена:{3},\nколичество = {4},\nprofit = {5}\n\n",
                            result.IndexOf(item) + 1, item.Category, item.Name, item.Price, item.Count,
                            algorithm.Profits[item]);
                    outputTb.Text += product;
                    writer.WriteLine(product);
                }
            }
        }

        private void richTextBox1_TextChanged(object sender, System.EventArgs e)
        {
        }

    }
}